//
//  ViewController.m
//  UICollectionView的小练习
//
//  Created by apple on 15/9/25.
//  Copyright © 2015年 信徒. All rights reserved.
//

#import "ViewController.h"
#import "LayoutTemplate.h"

@interface ViewController ()<UICollectionViewDelegateFlowLayout,UICollectionViewDataSource>

{
    NSArray *_imageArray;
    

}

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    

    
    
    _imageArray = @[@"5.jpg",@"1.jpg",@"123.jpg"];
   
    LayoutTemplate *layoutTemplate = [[LayoutTemplate alloc] init];
    
    UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0,80, self.view.frame.size.width, 300)collectionViewLayout:layoutTemplate];
    
    collectionView.dataSource = self;
    
    collectionView.delegate = self;
    
    [collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    
    //分页显示；
    collectionView.pagingEnabled = YES;
    
    //超过边界时关闭回弹效果；
    
    collectionView.bounces = NO;
    
    //关闭水平滚动条
    
    collectionView.showsHorizontalScrollIndicator = NO;
    collectionView.backgroundColor = [UIColor redColor];
    
    [self.view addSubview:collectionView];
    
}

#pragma mark - UICollectionSource

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 3;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];

    cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:_imageArray[indexPath.item]]];
    
//    cell.backgroundColor = indexPath.row%2?[UIColor orangeColor]:[UIColor greenColor];
    
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"%ld-->%ld",indexPath.item,indexPath.section);
}

#pragma mark - UICollectionDelegate

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(self.view.frame.size.width, 300);
}

//- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
//{
//    return 0.1;
//}

@end
